/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年8月5日
 */
package com.massyframework.beanskin.fragment;

import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

import com.massyframework.beanskin.ModuleIdentifier;
import com.massyframework.beanskin.ModuleRepository;
import com.massyframework.beanskin.RequireLibraryDescriptor;
import com.massyframework.beanskin.RequireLibraryDescriptors;
import com.massyframework.beanskin.library.LibraryBuilder;
import com.massyframework.beanskin.plugin.PluginBuilder;
import com.massyframework.beanskin.service.ServiceRepositoryFactory;
import com.massyframework.beanskin.util.classloading.ModuleClassLoader;

/**
 * 片段构建器
 * @author huangkh
 *
 */
public interface FragmentBuilder extends RequireLibraryDescriptors {

	/**
	 * 添加依赖类库
	 * @param value {@link RequireLibraryDescriptor}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder addRequireLibrary(RequireLibraryDescriptor value);
	
	/**
	 * 添加标签集
	 * @param value {@link Set}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder addTags(Set<String> value);
			
	/**
	 * 设置模块类加载器
	 * @param value {@link ModuleClassLoader}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder classLoader(ModuleClassLoader value);

	/**
	 * 设置模块简介
	 * @param value {@link String}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder description(String value);
	
	/**
	 * 设置解密公钥和要解密的类型
	 * @param publicKey {@link String},公钥
	 * @param x509Name {@link String},证书名称
	 * @param x509Encrypted {@link String},证书md5加密数据
	 * @param classNames {@link List}, 需要解密的类名集合
	 * @param scriptFileNames {@link List}, 需要解密的脚本文件, 文件路径应包括classpath的相对路径部份。
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder decryption(String publicKey, String x509Name, String x509Encrypted,List<String> classNames, List<String> scriptFileNames);
	
	/**
	 * 设置开发商
	 * @param shortName {@link String},简称
	 * @param name {@link String},全称
	 * @param homePage {@link String}, 主页
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder developer(String shortName, String name, String homePage);
	
	/**
	 * 模块标识符
	 * @return {@link ModuleIdentifier}
	 */
	ModuleIdentifier getModuleIdentifier();

	/**
	 * 设置模块标识符
	 * @param value {@link ModuleIdentifier}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder identifier(ModuleIdentifier value);
		
	/**
	 * 设置模块资源库
	 * @param value {@link ModuleRepository}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder moduleRepository(ModuleRepository value);
	
	/**
	 * 设置模块名称
	 * @param value {@link String}
	 * @return {@link LibraryBuilder}
	 */
	FragmentBuilder name(String value);
	
	/**
	 * 设置服务资源库工厂  
	 * @param facotry {@link ServiceRepositoryFactory}
	 * @return {@link FragmentBuilder}
	 */
	FragmentBuilder serviceRepositoryFactory(ServiceRepositoryFactory facotry);
	
	/**
	 * 设置参数, 不支持对存在参数进行覆写。
	 * @param name {@link String},参数名
	 * @param value {@link String},参数值
	 * @return {@link PluginBuilder}
	 */
	default FragmentBuilder setParameter(String name, String value) {
		return this.setParameter(name, value, null);
	}
	
	/**
	 * 设置参数, 不支持对存在参数进行覆写。
	 * @param name {@link String},参数名
	 * @param value {@link String},参数值
	 * @param action {@link Consumer},参数设置成功失败的回调方法,可以为null.
	 * @return {@link PluginBuilder}
	 */
	FragmentBuilder setParameter(String name, String value, Consumer<Boolean> action);
	
	/**
	 * 创建类库
	 * @return {@link Fragument}
	 */
	Fragment build();
}
